package com.zlm.spider.util;

import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @author Harbour
 * @date 2021-04-12 16:38
 */
@Component
public class PropertiesUtils {

    public static Properties getProperties(String propertiesName) {
        InputStream is = null;
        Properties properties = new Properties();
        try {
            is = ClassLoader.getSystemClassLoader().getResourceAsStream(propertiesName);
            if (is != null) {
                properties.load(new InputStreamReader(is, StandardCharsets.UTF_8));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    public static void main(String[] args) {
        Properties properties = PropertiesUtils.getProperties("img.properties");
        System.out.println(properties.getProperty("img.path") + "img/img.img");
    }

}
